import sys
import numpy as np
import os
import re

def display(res_path, eval_res_path, sm):
    colors = ["b", "g", "r"]
    markers = ["+", "p", "h", "o", "s", "<", ">", "1", "2", "3", "4", "H"]
    sum_ms = []
    import matplotlib.pyplot as plt
    plt.figure(figsize=(20,10),dpi=60)
    plt.rcParams['font.size'] = 12
    plt.grid(color='gray', linestyle='--', linewidth=1, alpha=0.5)
    
    res_path = res_path
    color = colors[0]
    meta_map = {}
    with open(res_path, 'r') as file:
        for line in file:
            items = line.split()
            # print(items)
            for id in range(9, 12, 2):
                if items[id] not in meta_map:
                    meta_map[items[id]] = ([], [])
                meta_map[items[id]][0].append(int(items[4]))
                meta_map[items[id]][1].append(float(items[id+1])/float(items[14]) )
    ms = list(meta_map.keys())
    for idx in range(len(ms)):
        x, y = np.array(meta_map[ms[idx]][0]), np.array(meta_map[ms[idx]][1])
        plt.plot(x, y, color=colors[idx], marker=markers[idx%len(markers)], linestyle='-')
    sum_ms += ms
    plt.plot(np.array(range(129)), np.array([1]*129), color=(0, 0, 0))
    plt.legend([f"{m}" for m in sum_ms]+["zhhao_qps_fp32"])            
    plt.xlabel('n')
    plt.ylabel('speedup')
    plt.title(f"int32/float32 {sm}")
    plt.savefig(eval_res_path)
    # plt.show()
    
if __name__ == "__main__":
    res_path = os.path.realpath(sys.argv[1])
    sm = sys.argv[2]
    eval_res_path = os.path.realpath(sys.argv[3])
    display(res_path, eval_res_path, sm)
